package com.cxl.sort;

/* Location:           E:\work\eclipse3.6_\workspace\design_pattern\
 * Qualified Name:     com.cxl.sort.QuickSort
 * JD-Core Version:    0.6.1
 */
public class QuickSort {
	public static void main(String[] args) {
		int[] array = { 6, 2, 7, 5, 3, 8, 9 };
		sort(array, 0, 6);
	}

	public static void sort(int[] arr, int low, int high) {
		int l = low;
		int h = high;
		int povit = arr[low];
		while (l < h) {
			while ((l < h) && (arr[h] >= povit))
				h--;
			if (l < h) {
				int temp = arr[h];
				arr[h] = arr[l];
				arr[l] = temp;
				l++;
			}
			int[] arrayOfInt = arr;
			int j = arr.length;
			for (int i = 0; i < j; i++) {
				int s = arrayOfInt[i];
				System.out.print(s + ",");
			}
			System.out.println("");
			while ((l < h) && (arr[l] <= povit))
				l++;
			if (l < h) {
				int temp = arr[h];
				arr[h] = arr[l];
				arr[l] = temp;
				h--;
			}
			arrayOfInt = arr;
			j = arr.length;
			for (int i = 0; i < j; i++) {
				int s = arrayOfInt[i];
				System.out.print(s + ",");
			}

			System.out.println("");
		}

		System.out.print("l=" + (l + 1) + ",h=" + (h + 1) + ",povit=" + povit + "\n");
		System.out.println("##############" + low + "##" + (h - 1));
		if (l > low)
			sort(arr, low, h - 1);
		if (h < high)
			sort(arr, l + 1, high);
	}
}